/*
package cn.whx.hrm.service.impl;

import cn.whx.hrm.domain.CourseType;
import cn.whx.hrm.mapper.CourseTypeMapper;
import cn.whx.hrm.service.ICourseTypeService;
import cn.whx.hrm.util.AjaxResult;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

*/
/**
 * <p>
 * 课程目录 服务实现类
 * </p>
 *
 * @author whx
 * @since 2021-06-21
 *//*

@Service
public class CourseTypeServiceImpl_cache extends ServiceImpl<CourseTypeMapper, CourseType> implements ICourseTypeService {
    @Autowired
    private CourseTypeMapper courseTypeMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public AjaxResult treeData() {
        */
/* List<CourseType> courseTypes =  courseTypeMapper.treeData();*//*

        List<CourseType> courseTypes =  threeType();
        return AjaxResult.me().setResultObj(courseTypes);
    }

    @Override
    @CacheEvict(cacheNames = "course_type_tree_data" ,key = "'type'")
    public boolean insert(CourseType entity) {
        return super.insert(entity);
    }

    @Override
    @CacheEvict(cacheNames = "course_type_tree_data" ,key = "'type'")
    public boolean update(CourseType entity, Wrapper<CourseType> wrapper) {
        return super.update(entity, wrapper);
    }

    @Override
    @CacheEvict(cacheNames = "course_type_tree_data" ,key = "'type'")
    public boolean deleteById(Serializable id) {
        return super.deleteById(id);
    }

    private List<CourseType> threeType() {
        List<CourseType> list = new ArrayList<>();
        //查询出所有东西
        List<CourseType> courseTypes = courseTypeMapper.selectList(null);
        HashMap<Long, CourseType> map = new HashMap<>();
        //id和对象的关系
        courseTypes.forEach(courseType -> {
            map.put(courseType.getId(), courseType);
        });
        //找爹，遍历数据
        courseTypes.stream().forEach(son -> {
            if (son.getPid()==0){ //找到最顶级 pid = 0
                //添加到里面去
                list.add(son);
            }else {//其他级别  pid要是和他id相等 就找到爹了
                CourseType courseType = map.get(son.getPid());
                //添加到子属性里去
                courseType.getChildren().add(son);
            }
        });
        return  list;
    }
}
*/
